﻿#include <QApplication>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QMessageBox>
#include "detection.h"
#include "result.h"
#include "login.h"
#include "regist.h"
#include "setting.h"
#include "history.h"
#include "forgetpassword.h"
#include "forgetpassword2.h"
#include "forgetpassword3.h"

#include"uploadimage.h"
#include<QTextCodec>

#include "connectionpool.h"
#include"titlebar.h"

//字符编码设为utf-8
//#pragma execution_character_set("utf-8")

#include<QDebug>
int main(int argc, char *argv[])
{

    QApplication a(argc, argv);

    QApplication::addLibraryPath("C:/Qt/Qt5.9.9/5.9.9/msvc2017_64/plugins");

    //链接数据库
//    QSqlDatabase db = ConnectionPool::openConnection();

    QSqlDatabase db =QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("106.52.184.134");
    db.setPort(3306);
    db.setDatabaseName("detection");
    db.setUserName("root");
    db.setPassword("123456789");

    db.setConnectOptions("MYSQL_OPT_RECONNECT=1");
//    //打印Qt支持的数据库驱动
//    qDebug()<<QSqlDatabase::drivers();

//    db.open();
//    qDebug()<<db.lastError();
    if(!db.open())
    {
        QMessageBox::information(NULL, QStringLiteral("连接失败"), db.lastError().text());
    }
    else
    {
//        QMessageBox::information(NULL, QStringLiteral("连接结果"), QStringLiteral("连接数据库成功"));
        titlebarFix *tBar=new titlebarFix;

        login *lo=new login;
        lo->setAttribute(Qt::WA_DeleteOnClose, true);

        lo->setAttribute(Qt::WA_DeleteOnClose);//设置关闭后销毁窗口

        tBar->setAttribute(Qt::WA_DeleteOnClose);//设置关闭后销毁窗口
        QObject::connect(lo,SIGNAL(sendsignal()),tBar,SLOT(close()));
        tBar->setMainWidget(lo);
//        tBar.setTitleBarIcon(QStringLiteral(":/images/软件图标.png"));
    //    tBar->setTitleBarText(QStringLiteral("登录界面"));
        //判断是否需要自动登录
        if(lo->autoLoginFlag&&lo->rememberPasswordFlag){

//            lo->show();
            tBar->show();
            lo->autoLoginByButton();
        }
        else {
            tBar->show();
    //        lo.show();
        }
//        QMessageBox::information(NULL, QStringLiteral("连接结果"), QStringLiteral("运行成功"));
    }

    return a.exec();
}
